Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./n1_n2_cleaned_cases.rds")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 856)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 13.04615 13.04154 13.03699 13.03248 13.02803 13.02363 13.01929 13.01499
## [9] 13.01074 13.00655 13.00240 12.99831 12.99426 12.99026 12.98631 12.98241
## [17] 12.97856 12.97476 12.97100 12.96729 12.96363 12.96002 12.95645 12.95293
## [25] 12.94946 12.94603 12.94264 12.93930 12.93601 12.93276 12.92956 12.92639
## [33] 12.92328 12.92020 12.91717 12.91418 12.91124 12.90834 12.90548 12.90266
## [41] 12.89988 12.89714 12.89445 12.89180 12.88922 12.88671 12.88425 12.88186
## [49] 12.87953 12.87726 12.87505 12.87291 12.87082 12.86880 12.86684 12.86494
## [57] 12.86309 12.86131 12.85959 12.85793 12.85633 12.85478 12.85330 12.85188
## [65] 12.85051 12.84920 12.84795 12.84676 12.84562 12.84454 12.84352 12.84256
## [73] 12.84165 12.84080 12.84001 12.83927 12.83859 12.83796 12.83739 12.83687
## [81] 12.83641 12.83600 12.83565 12.83535 12.83511 12.83492 12.83478 12.83470
## [89] 12.83467 12.83469 12.83476 12.83489 12.83509 12.83540 12.83582 12.83633
## [97] 12.83693 12.83763 12.83842 12.83930 12.84026 12.84130 12.84242 12.84362
## [105] 12.84489 12.84622 12.84763 12.84910 12.85062 12.85221 12.85385 12.85554
## [113] 12.85728 12.85907 12.86090 12.86277 12.86468 12.86662 12.86859 12.87059
## [121] 12.87262 12.87467 12.87673 12.87882 12.88092 12.88303 12.88514 12.88726
## [129] 12.88939 12.89151 12.89363 12.89574 12.89784 12.89993 12.90200 12.90480
## [137] 12.90899 12.91445 12.92108 12.92876 12.93738 12.94681 12.95696 12.96770
## [145] 12.97893 12.99052 13.00236 13.01435 13.02637 13.03829 13.05002 13.06143
## [153] 13.07242 13.08287 13.09266 13.10168 13.10982 13.11697 13.12300 13.12782
## [161] 13.13129 13.13444 13.13828 13.14278 13.14787 13.15349 13.15960 13.16612
## [169] 13.17301 13.18021 13.18766 13.19531 13.20309 13.21095 13.21884 13.22670
## [177] 13.23447 13.24209 13.24951 13.25667 13.26352 13.26999 13.27603 13.28159
## [185] 13.28660 13.29101 13.29477 13.29781 13.30009 13.30153 13.30210 13.30172
## [193] 13.30035 13.29792 13.29438 13.28968 13.28364 13.27621 13.26749 13.25759
## [201] 13.24660 13.23462 13.22176 13.20812 13.19380 13.17890 13.16353 13.14778
## [209] 13.13176 13.11556 13.09930 13.08307 13.06697 13.05111 13.03558 13.02049
## [217] 13.00595 12.99204 12.97888 12.96493 12.94871 12.93039 12.91016 12.88820
## [225] 12.86466 12.83975 12.81362 12.78647 12.75846 12.72977 12.70059 12.67108
## [233] 12.64143 12.61180 12.58239 12.55336 12.52489 12.49716 12.47035 12.44463
## [241] 12.42018 12.39718 12.37580 12.35623 12.33863 12.32203 12.30535 12.28862
## [249] 12.27185 12.25508 12.23831 12.22159 12.20493 12.18835 12.17188 12.15555
## [257] 12.13937 12.12337 12.10757 12.09200 12.07669 12.06165 12.04690 12.03248
## [265] 12.01841 12.00470 11.99191 11.98049 11.97033 11.96131 11.95333 11.94625
## [273] 11.93998 11.93440 11.92939 11.92484 11.92064 11.91667 11.91282 11.90898
## [281] 11.90503 11.90086 11.89635 11.89139 11.88587 11.87967 11.87268 11.86478
## [289] 11.85587 11.84627 11.83642 11.82635 11.81609 11.80568 11.79514 11.78452
## [297] 11.77384 11.76314 11.75244 11.74179 11.73121 11.72074 11.71040 11.70024
## [305] 11.69029 11.68057 11.67112 11.66198 11.65317 11.64473 11.63669 11.62909
## [313] 11.62195 11.61531 11.60920 11.60261 11.59460 11.58535 11.57501 11.56376
## [321] 11.55175 11.53916 11.52615 11.51288 11.49951 11.48622 11.47317 11.46052
## [329] 11.44844 11.43710 11.42665 11.41726 11.40911 11.40235 11.39715 11.39367
## [337] 11.39209 11.39256 11.39386 11.39471 11.39522 11.39547 11.39555 11.39556
## [345] 11.39558 11.39572 11.39606 11.39669 11.39771 11.39921 11.40129 11.40402
## [353] 11.40751 11.41185 11.41713 11.42344 11.43087 11.43952 11.44948 11.46166
## [361] 11.47678 11.49463 11.51500 11.53769 11.56248 11.58916 11.61754 11.64739
## [369] 11.67852 11.71072 11.74377 11.77747 11.81160 11.84597 11.88037 11.91458
## [377] 11.94839 11.98161 12.01402 12.04541 12.07558 12.10431 12.13140 12.15664
## [385] 12.17983 12.20075 12.21919 12.23733 12.25734 12.27904 12.30226 12.32680
## [393] 12.35249 12.37914 12.40657 12.43460 12.46305 12.49173 12.52047 12.54907
## [401] 12.57737 12.60516 12.63229 12.65855 12.68377 12.70777 12.73037 12.75137
## [409] 12.77061 12.78789 12.80304 12.81588 12.82621 12.83458 12.84170 12.84765
## [417] 12.85249 12.85632 12.85920 12.86121 12.86243 12.86293 12.86280 12.86210
## [425] 12.86092 12.85933 12.85742 12.85524 12.85289 12.85044 12.84797 12.84555
## [433] 12.84326 12.84117 12.83937 12.83793 12.83523 12.82977 12.82181 12.81162
## [441] 12.79947 12.78562 12.77034 12.75390 12.73655 12.71857 12.70023 12.68178
## [449] 12.66350 12.64565 12.62849 12.61229 12.59732 12.58385 12.57214 12.56245
## [457] 12.55505 12.54791 12.53894 12.52830 12.51615 12.50265 12.48797 12.47226
## [465] 12.45570 12.43844 12.42064 12.40248 12.38410 12.36568 12.34738 12.32936
## [473] 12.31178 12.29480 12.27859 12.26331 12.24913 12.23620 12.22468 12.21475
## [481] 12.20656 12.20028 12.19607 12.19336 12.19147 12.19034 12.18991 12.19015
## [489] 12.19100 12.19242 12.19434 12.19673 12.19952 12.20269 12.20616 12.20990
## [497] 12.21385 12.21796 12.22219 12.22648 12.23079 12.23507 12.23925 12.24331
## [505] 12.24717 12.25081 12.25558 12.26277 12.27220 12.28365 12.29696 12.31192
## [513] 12.32835 12.34605 12.36484 12.38452 12.40490 12.42580 12.44702 12.46837
## [521] 12.48966 12.51070 12.53131 12.55128 12.57042 12.58856 12.60549 12.62103
## [529] 12.63499 12.64717 12.65739 12.66545 12.67116 12.67434 12.67608 12.67760
## [537] 12.67891 12.67998 12.68082 12.68142 12.68176 12.68184 12.68166 12.68119
## [545] 12.68045 12.67942 12.67809 12.67645 12.67450 12.67222 12.66962 12.66668
## [553] 12.66340 12.65977 12.65577 12.65141 12.64667 12.64156 12.63605 12.63014
## [561] 12.62383 12.61710 12.60995 12.60237 12.59436 12.58590 12.57700 12.56646
## [569] 12.55328 12.53771 12.51999 12.50036 12.47906 12.45634 12.43244 12.40761
## [577] 12.38208 12.35610 12.32992 12.30377 12.27790 12.25255 12.22797 12.20440
## [585] 12.18208 12.16126 12.14217 12.12507 12.11019 12.09777 12.08561 12.07142
## [593] 12.05540 12.03774 12.01861 11.99820 11.97669 11.95428 11.93113 11.90745
## [601] 11.88341 11.85920 11.83500 11.81100 11.78738 11.76433 11.74203 11.72066
## [609] 11.70041 11.68147 11.66402 11.64824 11.63432 11.62244 11.61279 11.60555
## [617] 11.60020 11.59605 11.59303 11.59108 11.59013 11.59010 11.59094 11.59257
## [625] 11.59492 11.59793 11.60153 11.60565 11.61022 11.61517 11.62044 11.62595
## [633] 11.63165 11.63746 11.64331 11.64914 11.65487 11.66045 11.66579 11.67244
## [641] 11.68180 11.69361 11.70764 11.72362 11.74130 11.76042 11.78075 11.80202
## [649] 11.82398 11.84639 11.86898 11.89150 11.91371 11.93535 11.95616 11.97590
## [657] 11.99431 12.01115 12.02615 12.03907 12.05143 12.06489 12.07935 12.09472
## [665] 12.11092 12.12787 12.14546 12.16363 12.18227 12.20130 12.22064 12.24020
## [673] 12.25989 12.27962 12.29930 12.31885 12.33819 12.35722 12.37585 12.39400
## [681] 12.41159 12.42852 12.44471 12.46006 12.47450 12.48794 12.50028 12.51144
## [689] 12.52183 12.53191 12.54170 12.55120 12.56042 12.56938 12.57809 12.58655
## [697] 12.59479 12.60280 12.61059 12.61819 12.62560 12.63283 12.63989 12.64679
## [705] 12.65354 12.66016 12.66665 12.67303 12.67930 12.68548 12.69157 12.69759
## [713] 12.70355 12.70946 12.71515 12.72046 12.72541 12.73004 12.73436 12.73840
## [721] 12.74218 12.74574 12.74908 12.75225 12.75525 12.75812 12.76089 12.76356
## [729] 12.76618 12.76876 12.77134 12.77392 12.77654 12.77923 12.78200 12.78489
## [737] 12.78791 12.79085 12.79350 12.79586 12.79797 12.79983 12.80147 12.80289
## [745] 12.80413 12.80518 12.80608 12.80684 12.80747 12.80799 12.80842 12.80878
## [753] 12.80909 12.80935 12.80960 12.80983 12.81008 12.81036 12.81055 12.81053
## [761] 12.81031 12.80990 12.80932 12.80858 12.80768 12.80664 12.80547 12.80418
## [769] 12.80279 12.80131 12.79974 12.79810 12.79641 12.79466 12.79288 12.79108
## [777] 12.78927 12.78745 12.78565 12.78386 12.78212 12.78042 12.77878 12.77720
## [785] 12.77564 12.77402 12.77235 12.77062 12.76883 12.76698 12.76508 12.76311
## [793] 12.76109 12.75901 12.75686 12.75466 12.75239 12.75007 12.74768 12.74523
## [801] 12.74272 12.74014 12.73750 12.73480 12.73203 12.72920 12.72630 12.72334
## [809] 12.72031 12.71721 12.71405 12.71082 12.70752 12.70416 12.70074 12.69725
## [817] 12.69370 12.69008 12.68640 12.68266 12.67885 12.67497 12.67103 12.66703
## [825] 12.66295 12.65882 12.65461 12.65034 12.64600 12.64160 12.63713 12.63259
## [833] 12.62798 12.62331 12.61856 12.61375 12.60887 12.60393 12.59892 12.59384
## [841] 12.58869 12.58348 12.57820 12.57286 12.56745 12.56198 12.55644 12.55083
## [849] 12.54517 12.53943 12.53364 12.52778 12.52186 12.51587 12.50982 12.50371
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 856)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 12.58915 12.58592 12.58276 12.57967 12.57664 12.57368 12.57078 12.56796
## [9] 12.56520 12.56251 12.55989 12.55733 12.55485 12.55243 12.55008 12.54781
## [17] 12.54560 12.54347 12.54140 12.53941 12.53748 12.53563 12.53385 12.53215
## [25] 12.53051 12.52895 12.52746 12.52605 12.52471 12.52344 12.52225 12.52113
## [33] 12.52008 12.51912 12.51822 12.51741 12.51667 12.51600 12.51542 12.51490
## [41] 12.51447 12.51412 12.51384 12.51365 12.51356 12.51358 12.51369 12.51390
## [49] 12.51420 12.51460 12.51509 12.51567 12.51634 12.51711 12.51796 12.51890
## [57] 12.51992 12.52103 12.52222 12.52349 12.52485 12.52628 12.52779 12.52938
## [65] 12.53104 12.53278 12.53459 12.53648 12.53843 12.54045 12.54254 12.54470
## [73] 12.54692 12.54921 12.55156 12.55397 12.55645 12.55898 12.56157 12.56422
## [81] 12.56692 12.56968 12.57249 12.57535 12.57826 12.58122 12.58423 12.58728
## [89] 12.59039 12.59353 12.59672 12.59995 12.60334 12.60701 12.61094 12.61513
## [97] 12.61955 12.62421 12.62907 12.63414 12.63941 12.64485 12.65046 12.65622
## [105] 12.66213 12.66816 12.67432 12.68058 12.68694 12.69338 12.69989 12.70645
## [113] 12.71307 12.71971 12.72638 12.73306 12.73973 12.74639 12.75303 12.75962
## [121] 12.76616 12.77264 12.77905 12.78536 12.79158 12.79769 12.80367 12.80951
## [129] 12.81521 12.82075 12.82611 12.83129 12.83627 12.84169 12.84809 12.85540
## [137] 12.86351 12.87231 12.88170 12.89160 12.90189 12.91248 12.92327 12.93416
## [145] 12.94504 12.95582 12.96640 12.97668 12.98655 12.99593 13.00470 13.01277
## [153] 13.02003 13.02640 13.03176 13.03603 13.04029 13.04566 13.05207 13.05941
## [161] 13.06761 13.07658 13.08624 13.09650 13.10727 13.11848 13.13004 13.14185
## [169] 13.15385 13.16593 13.17802 13.19004 13.20189 13.21349 13.22476 13.23561
## [177] 13.24595 13.25571 13.26479 13.27312 13.28060 13.28716 13.29270 13.29714
## [185] 13.30040 13.30239 13.30302 13.30222 13.29989 13.29584 13.28997 13.28241
## [193] 13.27326 13.26265 13.25067 13.23745 13.22309 13.20771 13.19141 13.17432
## [201] 13.15654 13.13819 13.11937 13.10021 13.08080 13.06127 13.04173 13.02228
## [209] 13.00305 12.98414 12.96566 12.94773 12.93045 12.91395 12.89833 12.88371
## [217] 12.87019 12.85602 12.83948 12.82082 12.80024 12.77797 12.75423 12.72923
## [225] 12.70321 12.67637 12.64895 12.62116 12.59323 12.56537 12.53780 12.51075
## [233] 12.48444 12.45908 12.43490 12.41213 12.39097 12.37165 12.35440 12.33942
## [241] 12.32576 12.31230 12.29903 12.28595 12.27306 12.26035 12.24782 12.23547
## [249] 12.22329 12.21129 12.19945 12.18778 12.17628 12.16493 12.15374 12.14270
## [257] 12.13182 12.12108 12.11049 12.10004 12.08973 12.08026 12.07226 12.06561
## [265] 12.06021 12.05594 12.05269 12.05034 12.04878 12.04791 12.04761 12.04776
## [273] 12.04826 12.04899 12.04984 12.05069 12.05144 12.05198 12.05218 12.05194
## [281] 12.05114 12.04968 12.04744 12.04431 12.04017 12.03491 12.02843 12.02147
## [289] 12.01484 12.00852 12.00247 11.99666 11.99107 11.98566 11.98041 11.97529
## [297] 11.97027 11.96532 11.96041 11.95551 11.95059 11.94562 11.94058 11.93543
## [305] 11.93014 11.92469 11.91905 11.91318 11.90707 11.90067 11.89313 11.88373
## [313] 11.87263 11.86000 11.84600 11.83080 11.81456 11.79746 11.77964 11.76129
## [321] 11.74256 11.72362 11.70464 11.68578 11.66721 11.64909 11.63159 11.61488
## [329] 11.59911 11.58446 11.57109 11.55916 11.54885 11.54031 11.53372 11.52924
## [337] 11.52702 11.52573 11.52395 11.52178 11.51930 11.51662 11.51381 11.51097
## [345] 11.50819 11.50556 11.50317 11.50112 11.49949 11.49837 11.49786 11.49805
## [353] 11.49903 11.50088 11.50370 11.50759 11.51262 11.51890 11.52651 11.53617
## [361] 11.54843 11.56311 11.58003 11.59901 11.61987 11.64243 11.66652 11.69195
## [369] 11.71854 11.74613 11.77452 11.80354 11.83301 11.86275 11.89258 11.92233
## [377] 11.95181 11.98085 12.00927 12.03688 12.06352 12.08899 12.11313 12.13575
## [385] 12.15667 12.17572 12.19271 12.20976 12.22896 12.25012 12.27304 12.29750
## [393] 12.32333 12.35030 12.37824 12.40692 12.43617 12.46576 12.49552 12.52523
## [401] 12.55469 12.58371 12.61209 12.63962 12.66612 12.69136 12.71517 12.73733
## [409] 12.75764 12.77592 12.79195 12.80554 12.81649 12.82573 12.83434 12.84233
## [417] 12.84971 12.85650 12.86271 12.86836 12.87345 12.87799 12.88201 12.88551
## [425] 12.88851 12.89102 12.89305 12.89461 12.89572 12.89639 12.89664 12.89647
## [433] 12.89591 12.89495 12.89362 12.89192 12.88831 12.88141 12.87155 12.85906
## [441] 12.84424 12.82744 12.80896 12.78912 12.76825 12.74668 12.72471 12.70267
## [449] 12.68088 12.65967 12.63935 12.62025 12.60268 12.58697 12.57344 12.56241
## [457] 12.55419 12.54640 12.53655 12.52481 12.51138 12.49645 12.48019 12.46279
## [465] 12.44445 12.42534 12.40565 12.38557 12.36529 12.34498 12.32484 12.30506
## [473] 12.28581 12.26729 12.24968 12.23317 12.21793 12.20417 12.19206 12.18180
## [481] 12.17356 12.16753 12.16390 12.16177 12.16010 12.15888 12.15810 12.15774
## [489] 12.15779 12.15825 12.15910 12.16032 12.16191 12.16385 12.16613 12.16874
## [497] 12.17166 12.17489 12.17841 12.18221 12.18628 12.19061 12.19517 12.19997
## [505] 12.20499 12.21021 12.21710 12.22696 12.23957 12.25469 12.27211 12.29160
## [513] 12.31294 12.33588 12.36022 12.38572 12.41216 12.43930 12.46693 12.49482
## [521] 12.52274 12.55047 12.57777 12.60443 12.63021 12.65490 12.67826 12.70006
## [529] 12.72009 12.73811 12.75391 12.76724 12.77789 12.78563 12.79210 12.79904
## [537] 12.80639 12.81410 12.82210 12.83033 12.83875 12.84728 12.85586 12.86444
## [545] 12.87296 12.88136 12.88958 12.89756 12.90524 12.91255 12.91945 12.92587
## [553] 12.93175 12.93704 12.94167 12.94558 12.94871 12.95101 12.95242 12.95287
## [561] 12.95231 12.95067 12.94790 12.94394 12.93873 12.93220 12.92431 12.91389
## [569] 12.90002 12.88301 12.86317 12.84079 12.81619 12.78966 12.76151 12.73205
## [577] 12.70157 12.67038 12.63879 12.60709 12.57560 12.54461 12.51444 12.48537
## [585] 12.45773 12.43180 12.40790 12.38633 12.36739 12.35139 12.33552 12.31693
## [593] 12.29587 12.27257 12.24728 12.22025 12.19170 12.16188 12.13104 12.09942
## [601] 12.06725 12.03478 12.00225 11.96990 11.93797 11.90671 11.87635 11.84714
## [609] 11.81931 11.79312 11.76880 11.74659 11.72673 11.70947 11.69505 11.68370
## [617] 11.67430 11.66554 11.65741 11.64991 11.64303 11.63675 11.63107 11.62599
## [625] 11.62149 11.61756 11.61420 11.61139 11.60914 11.60743 11.60625 11.60560
## [633] 11.60546 11.60583 11.60670 11.60807 11.60991 11.61223 11.61502 11.61956
## [641] 11.62698 11.63702 11.64942 11.66393 11.68029 11.69825 11.71755 11.73794
## [649] 11.75915 11.78094 11.80305 11.82521 11.84719 11.86871 11.88953 11.90938
## [657] 11.92802 11.94518 11.96062 11.97406 11.98732 12.00228 12.01881 12.03678
## [665] 12.05608 12.07656 12.09811 12.12060 12.14390 12.16789 12.19244 12.21742
## [673] 12.24271 12.26818 12.29371 12.31917 12.34443 12.36937 12.39385 12.41777
## [681] 12.44097 12.46335 12.48478 12.50512 12.52426 12.54206 12.55840 12.57316
## [689] 12.58705 12.60087 12.61462 12.62828 12.64185 12.65531 12.66866 12.68189
## [697] 12.69499 12.70795 12.72077 12.73342 12.74591 12.75822 12.77035 12.78229
## [705] 12.79402 12.80554 12.81684 12.82791 12.83875 12.84933 12.85966 12.86973
## [713] 12.87952 12.88902 12.89827 12.90730 12.91610 12.92468 12.93305 12.94120
## [721] 12.94914 12.95688 12.96441 12.97174 12.97887 12.98580 12.99254 12.99909
## [729] 13.00546 13.01163 13.01763 13.02345 13.02909 13.03456 13.03985 13.04498
## [737] 13.04995 13.05480 13.05959 13.06429 13.06889 13.07337 13.07773 13.08194
## [745] 13.08600 13.08988 13.09357 13.09707 13.10035 13.10339 13.10620 13.10874
## [753] 13.11100 13.11298 13.11466 13.11601 13.11703 13.11771 13.11790 13.11753
## [761] 13.11662 13.11521 13.11335 13.11106 13.10838 13.10536 13.10204 13.09844
## [769] 13.09460 13.09057 13.08639 13.08208 13.07769 13.07325 13.06881 13.06439
## [777] 13.06004 13.05580 13.05170 13.04778 13.04408 13.04064 13.03749 13.03466
## [785] 13.03193 13.02903 13.02596 13.02274 13.01936 13.01584 13.01218 13.00839
## [793] 13.00447 13.00043 12.99628 12.99202 12.98766 12.98321 12.97867 12.97405
## [801] 12.96936 12.96460 12.95978 12.95491 12.94999 12.94503 12.94003 12.93500
## [809] 12.92995 12.92489 12.91982 12.91474 12.90962 12.90439 12.89905 12.89362
## [817] 12.88808 12.88246 12.87674 12.87093 12.86504 12.85906 12.85301 12.84687
## [825] 12.84066 12.83438 12.82803 12.82161 12.81513 12.80859 12.80198 12.79533
## [833] 12.78861 12.78185 12.77504 12.76821 12.76137 12.75452 12.74765 12.74076
## [841] 12.73385 12.72691 12.71994 12.71292 12.70587 12.69877 12.69161 12.68440
## [849] 12.67713 12.66980 12.66240 12.65492 12.64736 12.63972 12.63200 12.62418
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 856)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 12.04521 12.03873 12.03234 12.02605 12.01986 12.01376 12.00776 12.00185
## [9] 11.99604 11.99031 11.98469 11.97915 11.97371 11.96836 11.96311 11.95795
## [17] 11.95287 11.94789 11.94301 11.93821 11.93350 11.92888 11.92436 11.91992
## [25] 11.91557 11.91131 11.90714 11.90306 11.89906 11.89516 11.89134 11.88761
## [33] 11.88396 11.88041 11.87694 11.87355 11.87025 11.86704 11.86391 11.86086
## [41] 11.85790 11.85503 11.85223 11.84953 11.84690 11.84436 11.84190 11.83952
## [49] 11.83723 11.83501 11.83290 11.83091 11.82905 11.82730 11.82568 11.82417
## [57] 11.82278 11.82151 11.82036 11.81932 11.81839 11.81757 11.81687 11.81628
## [65] 11.81579 11.81542 11.81515 11.81499 11.81493 11.81498 11.81513 11.81538
## [73] 11.81573 11.81619 11.81674 11.81739 11.81813 11.81897 11.81991 11.82094
## [81] 11.82206 11.82327 11.82457 11.82596 11.82744 11.82901 11.83066 11.83240
## [89] 11.83422 11.83613 11.83811 11.84018 11.84232 11.84455 11.84685 11.84923
## [97] 11.85168 11.85421 11.85681 11.85955 11.86249 11.86561 11.86893 11.87243
## [105] 11.87611 11.87997 11.88399 11.88817 11.89252 11.89702 11.90166 11.90645
## [113] 11.91138 11.91645 11.92164 11.92696 11.93240 11.93795 11.94361 11.94938
## [121] 11.95524 11.96120 11.96726 11.97339 11.97961 11.98590 11.99226 11.99869
## [129] 12.00517 12.01172 12.01831 12.02495 12.03163 12.03834 12.04509 12.05303
## [137] 12.06323 12.07550 12.08967 12.10555 12.12297 12.14175 12.16170 12.18266
## [145] 12.20443 12.22685 12.24974 12.27290 12.29617 12.31937 12.34232 12.36483
## [153] 12.38674 12.40785 12.42800 12.44700 12.46468 12.48085 12.49533 12.50796
## [161] 12.51854 12.52852 12.53941 12.55114 12.56361 12.57677 12.59052 12.60480
## [169] 12.61952 12.63460 12.64998 12.66557 12.68130 12.69708 12.71284 12.72851
## [177] 12.74400 12.75924 12.77415 12.78866 12.80268 12.81614 12.82896 12.84106
## [185] 12.85237 12.86281 12.87230 12.88077 12.88813 12.89431 12.89923 12.90282
## [193] 12.90500 12.90568 12.90480 12.90227 12.89741 12.88971 12.87942 12.86676
## [201] 12.85196 12.83524 12.81684 12.79699 12.77591 12.75384 12.73099 12.70761
## [209] 12.68392 12.66015 12.63652 12.61328 12.59063 12.56883 12.54808 12.52863
## [217] 12.51070 12.49452 12.48032 12.46613 12.44994 12.43191 12.41220 12.39096
## [225] 12.36836 12.34456 12.31971 12.29397 12.26751 12.24048 12.21305 12.18536
## [233] 12.15759 12.12988 12.10241 12.07532 12.04878 12.02295 11.99798 11.97404
## [241] 11.95128 11.92987 11.90996 11.89171 11.87529 11.86002 11.84514 11.83061
## [249] 11.81640 11.80249 11.78884 11.77544 11.76225 11.74925 11.73640 11.72369
## [257] 11.71107 11.69854 11.68605 11.67358 11.66111 11.64860 11.63602 11.62336
## [265] 11.61058 11.59765 11.58499 11.57300 11.56163 11.55084 11.54058 11.53081
## [273] 11.52148 11.51255 11.50398 11.49571 11.48770 11.47991 11.47230 11.46481
## [281] 11.45741 11.45004 11.44267 11.43525 11.42773 11.42007 11.41223 11.40415
## [289] 11.39580 11.38736 11.37906 11.37090 11.36288 11.35501 11.34730 11.33974
## [297] 11.33235 11.32512 11.31806 11.31118 11.30447 11.29795 11.29161 11.28547
## [305] 11.27951 11.27376 11.26822 11.26288 11.25775 11.25284 11.24814 11.24368
## [313] 11.23944 11.23543 11.23166 11.22712 11.22091 11.21322 11.20423 11.19413
## [321] 11.18309 11.17130 11.15894 11.14621 11.13327 11.12032 11.10753 11.09509
## [329] 11.08319 11.07201 11.06172 11.05252 11.04459 11.03810 11.03325 11.03022
## [337] 11.02918 11.03033 11.03280 11.03562 11.03879 11.04233 11.04624 11.05054
## [345] 11.05522 11.06031 11.06581 11.07173 11.07808 11.08487 11.09211 11.09981
## [353] 11.10797 11.11661 11.12574 11.13536 11.14548 11.15612 11.16728 11.18009
## [361] 11.19555 11.21346 11.23363 11.25588 11.28002 11.30585 11.33320 11.36185
## [369] 11.39164 11.42237 11.45384 11.48587 11.51828 11.55086 11.58343 11.61581
## [377] 11.64780 11.67921 11.70985 11.73953 11.76807 11.79527 11.82094 11.84490
## [385] 11.86696 11.88692 11.90460 11.92171 11.94001 11.95938 11.97970 12.00085
## [393] 12.02269 12.04511 12.06798 12.09118 12.11458 12.13807 12.16151 12.18479
## [401] 12.20777 12.23035 12.25238 12.27376 12.29435 12.31403 12.33268 12.35018
## [409] 12.36639 12.38121 12.39449 12.40613 12.41599 12.42455 12.43236 12.43947
## [417] 12.44591 12.45171 12.45691 12.46154 12.46564 12.46924 12.47237 12.47507
## [425] 12.47737 12.47930 12.48091 12.48222 12.48327 12.48409 12.48472 12.48519
## [433] 12.48554 12.48580 12.48599 12.48617 12.48534 12.48259 12.47812 12.47208
## [441] 12.46466 12.45603 12.44635 12.43581 12.42458 12.41283 12.40074 12.38847
## [449] 12.37620 12.36411 12.35237 12.34115 12.33063 12.32098 12.31237 12.30498
## [457] 12.29897 12.29272 12.28457 12.27468 12.26322 12.25036 12.23624 12.22104
## [465] 12.20492 12.18804 12.17057 12.15266 12.13449 12.11621 12.09798 12.07997
## [473] 12.06234 12.04526 12.02889 12.01338 11.99891 11.98563 11.97372 11.96332
## [481] 11.95461 11.94775 11.94289 11.93900 11.93493 11.93074 11.92648 11.92219
## [489] 11.91790 11.91369 11.90957 11.90561 11.90185 11.89833 11.89511 11.89222
## [497] 11.88971 11.88763 11.88603 11.88494 11.88443 11.88452 11.88527 11.88673
## [505] 11.88894 11.89194 11.89652 11.90330 11.91213 11.92284 11.93527 11.94925
## [513] 11.96461 11.98119 11.99883 12.01736 12.03661 12.05642 12.07663 12.09708
## [521] 12.11758 12.13799 12.15813 12.17785 12.19697 12.21533 12.23277 12.24912
## [529] 12.26422 12.27790 12.28999 12.30034 12.30877 12.31513 12.32069 12.32680
## [537] 12.33341 12.34048 12.34794 12.35575 12.36386 12.37222 12.38076 12.38945
## [545] 12.39823 12.40704 12.41584 12.42458 12.43320 12.44165 12.44988 12.45783
## [553] 12.46546 12.47272 12.47955 12.48590 12.49171 12.49695 12.50155 12.50546
## [561] 12.50864 12.51103 12.51258 12.51323 12.51294 12.51165 12.50932 12.50549
## [569] 12.49984 12.49254 12.48373 12.47357 12.46221 12.44980 12.43649 12.42245
## [577] 12.40781 12.39274 12.37739 12.36190 12.34644 12.33115 12.31620 12.30172
## [585] 12.28788 12.27482 12.26270 12.25168 12.24190 12.23352 12.22464 12.21340
## [593] 12.20001 12.18466 12.16755 12.14888 12.12885 12.10765 12.08550 12.06258
## [601] 12.03909 12.01524 11.99123 11.96725 11.94350 11.92018 11.89750 11.87564
## [609] 11.85482 11.83522 11.81705 11.80051 11.78580 11.77311 11.76264 11.75460
## [617] 11.74810 11.74212 11.73664 11.73165 11.72713 11.72307 11.71947 11.71629
## [625] 11.71354 11.71119 11.70923 11.70765 11.70644 11.70558 11.70506 11.70486
## [633] 11.70497 11.70537 11.70606 11.70702 11.70824 11.70969 11.71138 11.71438
## [641] 11.71964 11.72695 11.73611 11.74690 11.75911 11.77253 11.78696 11.80218
## [649] 11.81797 11.83414 11.85047 11.86674 11.88276 11.89830 11.91316 11.92713
## [657] 11.93999 11.95154 11.96157 11.96986 11.97768 11.98638 11.99590 12.00617
## [665] 12.01710 12.02865 12.04073 12.05327 12.06621 12.07948 12.09300 12.10672
## [673] 12.12054 12.13442 12.14828 12.16204 12.17564 12.18901 12.20208 12.21477
## [681] 12.22703 12.23878 12.24995 12.26047 12.27026 12.27928 12.28743 12.29465
## [689] 12.30124 12.30756 12.31362 12.31944 12.32502 12.33040 12.33557 12.34056
## [697] 12.34538 12.35005 12.35457 12.35898 12.36327 12.36747 12.37160 12.37566
## [705] 12.37967 12.38365 12.38761 12.39156 12.39553 12.39953 12.40357 12.40767
## [713] 12.41183 12.41609 12.42018 12.42386 12.42716 12.43012 12.43276 12.43511
## [721] 12.43721 12.43907 12.44075 12.44226 12.44363 12.44490 12.44609 12.44725
## [729] 12.44839 12.44954 12.45075 12.45203 12.45342 12.45495 12.45665 12.45855
## [737] 12.46068 12.46301 12.46547 12.46803 12.47069 12.47340 12.47617 12.47895
## [745] 12.48174 12.48450 12.48722 12.48988 12.49246 12.49493 12.49727 12.49946
## [753] 12.50149 12.50332 12.50494 12.50632 12.50745 12.50830 12.50891 12.50936
## [761] 12.50964 12.50976 12.50975 12.50960 12.50934 12.50896 12.50847 12.50790
## [769] 12.50724 12.50652 12.50573 12.50489 12.50400 12.50309 12.50216 12.50121
## [777] 12.50026 12.49932 12.49840 12.49751 12.49666 12.49586 12.49511 12.49444
## [785] 12.49378 12.49309 12.49235 12.49158 12.49077 12.48992 12.48904 12.48810
## [793] 12.48713 12.48612 12.48506 12.48396 12.48282 12.48163 12.48040 12.47912
## [801] 12.47779 12.47642 12.47500 12.47354 12.47202 12.47046 12.46885 12.46718
## [809] 12.46547 12.46371 12.46189 12.46002 12.45810 12.45614 12.45412 12.45206
## [817] 12.44995 12.44779 12.44558 12.44333 12.44103 12.43868 12.43628 12.43384
## [825] 12.43135 12.42881 12.42622 12.42358 12.42090 12.41817 12.41540 12.41257
## [833] 12.40970 12.40679 12.40382 12.40081 12.39777 12.39468 12.39156 12.38840
## [841] 12.38520 12.38195 12.37867 12.37535 12.37198 12.36857 12.36512 12.36163
## [849] 12.35810 12.35452 12.35090 12.34723 12.34352 12.33976 12.33596 12.33211
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
save(both_ymina, file = "./plotly_objs/both_ymina.rda")
save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
save(both_yminb, file = "./plotly_objs/both_yminb.rda")
save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
save(both_yminc, file = "./plotly_objs/both_yminc.rda")
save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")